package xworker.javafx.scene;

import javafx.geometry.NodeOrientation;
import javafx.geometry.Point3D;
import javafx.scene.*;
import javafx.scene.effect.BlendMode;
import org.xmeta.ActionContext;
import org.xmeta.Thing;
import xworker.javafx.beans.property.PropertyFactory;
import xworker.javafx.design.Designer;
import xworker.javafx.util.JavaFXUtils;

public class NodeActions {
    static{
        PropertyFactory.regist(Node.class, "eventDispatcherProperty", o -> {
            Node obj = (Node) o;
            return obj.eventDispatcherProperty();
        });
        PropertyFactory.regist(Node.class, "opacityProperty", o -> {
            Node obj = (Node) o;
            return obj.opacityProperty();
        });
        PropertyFactory.regist(Node.class, "blendModeProperty", o -> {
            Node obj = (Node) o;
            return obj.blendModeProperty();
        });
        PropertyFactory.regist(Node.class, "depthTestProperty", o -> {
            Node obj = (Node) o;
            return obj.depthTestProperty();
        });
        PropertyFactory.regist(Node.class, "cacheProperty", o -> {
            Node obj = (Node) o;
            return obj.cacheProperty();
        });
        PropertyFactory.regist(Node.class, "cursorProperty", o -> {
            Node obj = (Node) o;
            return obj.cursorProperty();
        });
        PropertyFactory.regist(Node.class, "styleProperty", o -> {
            Node obj = (Node) o;
            return obj.styleProperty();
        });
        PropertyFactory.regist(Node.class, "clipProperty", o -> {
            Node obj = (Node) o;
            return obj.clipProperty();
        });
        PropertyFactory.regist(Node.class, "cacheHintProperty", o -> {
            Node obj = (Node) o;
            return obj.cacheHintProperty();
        });
        PropertyFactory.regist(Node.class, "onDragOverProperty", o -> {
            Node obj = (Node) o;
            return obj.onDragOverProperty();
        });
        PropertyFactory.regist(Node.class, "effectProperty", o -> {
            Node obj = (Node) o;
            return obj.effectProperty();
        });
        PropertyFactory.regist(Node.class, "managedProperty", o -> {
            Node obj = (Node) o;
            return obj.managedProperty();
        });
        PropertyFactory.regist(Node.class, "layoutYProperty", o -> {
            Node obj = (Node) o;
            return obj.layoutYProperty();
        });
        PropertyFactory.regist(Node.class, "onDragDoneProperty", o -> {
            Node obj = (Node) o;
            return obj.onDragDoneProperty();
        });
        PropertyFactory.regist(Node.class, "layoutXProperty", o -> {
            Node obj = (Node) o;
            return obj.layoutXProperty();
        });
        PropertyFactory.regist(Node.class, "scaleXProperty", o -> {
            Node obj = (Node) o;
            return obj.scaleXProperty();
        });
        PropertyFactory.regist(Node.class, "translateYProperty", o -> {
            Node obj = (Node) o;
            return obj.translateYProperty();
        });
        PropertyFactory.regist(Node.class, "translateZProperty", o -> {
            Node obj = (Node) o;
            return obj.translateZProperty();
        });
        PropertyFactory.regist(Node.class, "onRotateProperty", o -> {
            Node obj = (Node) o;
            return obj.onRotateProperty();
        });
        PropertyFactory.regist(Node.class, "onSwipeUpProperty", o -> {
            Node obj = (Node) o;
            return obj.onSwipeUpProperty();
        });
        PropertyFactory.regist(Node.class, "onScrollProperty", o -> {
            Node obj = (Node) o;
            return obj.onScrollProperty();
        });
        PropertyFactory.regist(Node.class, "onZoomProperty", o -> {
            Node obj = (Node) o;
            return obj.onZoomProperty();
        });
        PropertyFactory.regist(Node.class, "rotateProperty", o -> {
            Node obj = (Node) o;
            return obj.rotateProperty();
        });
        PropertyFactory.regist(Node.class, "scaleYProperty", o -> {
            Node obj = (Node) o;
            return obj.scaleYProperty();
        });
        PropertyFactory.regist(Node.class, "scaleZProperty", o -> {
            Node obj = (Node) o;
            return obj.scaleZProperty();
        });
        PropertyFactory.regist(Node.class, "translateXProperty", o -> {
            Node obj = (Node) o;
            return obj.translateXProperty();
        });

        PropertyFactory.regist(Node.class, "onKeyTypedProperty", o -> {
            Node obj = (Node) o;
            return obj.onKeyTypedProperty();
        });
        PropertyFactory.regist(Node.class, "pickOnBoundsProperty", o -> {
            Node obj = (Node) o;
            return obj.pickOnBoundsProperty();
        });
        PropertyFactory.regist(Node.class, "onDragEnteredProperty", o -> {
            Node obj = (Node) o;
            return obj.onDragEnteredProperty();
        });
        PropertyFactory.regist(Node.class, "rotationAxisProperty", o -> {
            Node obj = (Node) o;
            return obj.rotationAxisProperty();
        });
        PropertyFactory.regist(Node.class, "onDragExitedProperty", o -> {
            Node obj = (Node) o;
            return obj.onDragExitedProperty();
        });
        PropertyFactory.regist(Node.class, "onDragDroppedProperty", o -> {
            Node obj = (Node) o;
            return obj.onDragDroppedProperty();
        });
        PropertyFactory.regist(Node.class, "onZoomFinishedProperty", o -> {
            Node obj = (Node) o;
            return obj.onZoomFinishedProperty();
        });
        PropertyFactory.regist(Node.class, "onKeyPressedProperty", o -> {
            Node obj = (Node) o;
            return obj.onKeyPressedProperty();
        });
        PropertyFactory.regist(Node.class, "onInputMethodTextChangedProperty", o -> {
            Node obj = (Node) o;
            return obj.onInputMethodTextChangedProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseDraggedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseDraggedProperty();
        });
        PropertyFactory.regist(Node.class, "focusTraversableProperty", o -> {
            Node obj = (Node) o;
            return obj.focusTraversableProperty();
        });
        PropertyFactory.regist(Node.class, "onZoomStartedProperty", o -> {
            Node obj = (Node) o;
            return obj.onZoomStartedProperty();
        });
        PropertyFactory.regist(Node.class, "onSwipeDownProperty", o -> {
            Node obj = (Node) o;
            return obj.onSwipeDownProperty();
        });
        PropertyFactory.regist(Node.class, "onSwipeLeftProperty", o -> {
            Node obj = (Node) o;
            return obj.onSwipeLeftProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseDragReleasedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseDragReleasedProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseClickedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseClickedProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseDragOverProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseDragOverProperty();
        });
        PropertyFactory.regist(Node.class, "mouseTransparentProperty", o -> {
            Node obj = (Node) o;
            return obj.mouseTransparentProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseEnteredProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseEnteredProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseExitedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseExitedProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseDragExitedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseDragExitedProperty();
        });
        PropertyFactory.regist(Node.class, "onMousePressedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMousePressedProperty();
        });
        PropertyFactory.regist(Node.class, "onScrollStartedProperty", o -> {
            Node obj = (Node) o;
            return obj.onScrollStartedProperty();
        });
        PropertyFactory.regist(Node.class, "onTouchReleasedProperty", o -> {
            Node obj = (Node) o;
            return obj.onTouchReleasedProperty();
        });
        PropertyFactory.regist(Node.class, "onKeyReleasedProperty", o -> {
            Node obj = (Node) o;
            return obj.onKeyReleasedProperty();
        });
        PropertyFactory.regist(Node.class, "inputMethodRequestsProperty", o -> {
            Node obj = (Node) o;
            return obj.inputMethodRequestsProperty();
        });
        PropertyFactory.regist(Node.class, "onDragDetectedProperty", o -> {
            Node obj = (Node) o;
            return obj.onDragDetectedProperty();
        });
        PropertyFactory.regist(Node.class, "nodeOrientationProperty", o -> {
            Node obj = (Node) o;
            return obj.nodeOrientationProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseMovedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseMovedProperty();
        });
        PropertyFactory.regist(Node.class, "onScrollFinishedProperty", o -> {
            Node obj = (Node) o;
            return obj.onScrollFinishedProperty();
        });
        PropertyFactory.regist(Node.class, "onRotationStartedProperty", o -> {
            Node obj = (Node) o;
            return obj.onRotationStartedProperty();
        });
        PropertyFactory.regist(Node.class, "onRotationFinishedProperty", o -> {
            Node obj = (Node) o;
            return obj.onRotationFinishedProperty();
        });
        PropertyFactory.regist(Node.class, "onTouchPressedProperty", o -> {
            Node obj = (Node) o;
            return obj.onTouchPressedProperty();
        });
        PropertyFactory.regist(Node.class, "onSwipeRightProperty", o -> {
            Node obj = (Node) o;
            return obj.onSwipeRightProperty();
        });
        PropertyFactory.regist(Node.class, "onContextMenuRequestedProperty", o -> {
            Node obj = (Node) o;
            return obj.onContextMenuRequestedProperty();
        });
        PropertyFactory.regist(Node.class, "onTouchMovedProperty", o -> {
            Node obj = (Node) o;
            return obj.onTouchMovedProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseReleasedProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseReleasedProperty();
        });
        PropertyFactory.regist(Node.class, "onTouchStationaryProperty", o -> {
            Node obj = (Node) o;
            return obj.onTouchStationaryProperty();
        });
        PropertyFactory.regist(Node.class, "onMouseDragEnteredProperty", o -> {
            Node obj = (Node) o;
            return obj.onMouseDragEnteredProperty();
        });
        PropertyFactory.regist(Node.class, "accessibleHelpProperty", o -> {
            Node obj = (Node) o;
            return obj.accessibleHelpProperty();
        });
        PropertyFactory.regist(Node.class, "accessibleRoleProperty", o -> {
            Node obj = (Node) o;
            return obj.accessibleRoleProperty();
        });
        PropertyFactory.regist(Node.class, "accessibleTextProperty", o -> {
            Node obj = (Node) o;
            return obj.accessibleTextProperty();
        });
        PropertyFactory.regist(Node.class, "accessibleRoleDescriptionProperty", o -> {
            Node obj = (Node) o;
            return obj.accessibleRoleDescriptionProperty();
        });
        PropertyFactory.regist(Node.class, "idProperty", o -> {
            Node obj = (Node) o;
            return obj.idProperty();
        });
        PropertyFactory.regist(Node.class, "disableProperty", o -> {
            Node obj = (Node) o;
            return obj.disableProperty();
        });
        PropertyFactory.regist(Node.class, "visibleProperty", o -> {
            Node obj = (Node) o;
            return obj.visibleProperty();
        });
    }

	public static void init(Node node, Thing thing, ActionContext actionContext) {
        if(thing.valueExists("id")){
            node.setId(thing.getString("id"));
        }
        if(thing.valueExists("accessibleHelp")){
            node.setAccessibleHelp(thing.getString("accessibleHelp"));
        }
        if(thing.valueExists("accessibleRoleDescription")){
            node.setAccessibleRoleDescription(thing.getString("accessibleRoleDescription"));
        }
        if(thing.valueExists("accessibleRole")){
            node.setAccessibleRole(AccessibleRole.valueOf(thing.getString("accessibleRole")));
        }
        if(thing.valueExists("accessibleText")){
            node.setAccessibleText(thing.getString("accessibleText"));
        }
        if(thing.valueExists("blendMode")){
            node.setBlendMode(BlendMode.valueOf(thing.getString("blendMode")));
        }
        if(thing.valueExists("cacheHint")){
            node.setCacheHint(CacheHint.valueOf(thing.getString("cacheHint")));
        }
        if(thing.valueExists("cache")){
            node.setCache(thing.getBoolean("cache"));
        }
        if(thing.valueExists("cursor")){
        	Cursor cursor = JavaFXUtils.getCursor(thing.getString("cursor"));
        	if(cursor != null) {
        		node.setCursor(cursor);
        	}
        }
        if(thing.valueExists("depthTest")){
            node.setDepthTest(DepthTest.valueOf(thing.getString("depthTest")));
        }
        if(thing.valueExists("disable")){
            node.setDisable(thing.getBoolean("disable"));
        }
        if(thing.valueExists("focusTraversable")){
            node.setFocusTraversable(thing.getBoolean("focusTraversable"));
        }
        if(thing.valueExists("layoutX")){
            node.setLayoutX(thing.getDouble("layoutX"));
        }
        if(thing.valueExists("layoutY")){
            node.setLayoutY(thing.getDouble("layoutY"));
        }
        if(thing.valueExists("managed")){
            node.setManaged(thing.getBoolean("managed"));
        }
        if(thing.valueExists("mouseTransparent")){
            node.setMouseTransparent(thing.getBoolean("mouseTransparent"));
        }
        if(thing.valueExists("nodeOrientation")){
            node.setNodeOrientation(NodeOrientation.valueOf(thing.getString("nodeOrientation")));
        }
        if(thing.valueExists("opacity")){
            node.setOpacity(thing.getDouble("opacity"));
        }
        if(thing.valueExists("pickOnBounds")){
            node.setPickOnBounds(thing.getBoolean("pickOnBounds"));
        }
        if(thing.valueExists("rotate")){
            node.setRotate(thing.getDouble("rotate"));
        }
        if(thing.valueExists("rotationAxis")){
        	Point3D point = JavaFXUtils.getPoint3D(thing.getString("rotationAxis"));
        	if(point != null) {
        		node.setRotationAxis(point);
        	}
        }
        if(thing.valueExists("scaleX")){
            node.setScaleX(thing.getDouble("scaleX"));
        }
        if(thing.valueExists("scaleY")){
            node.setScaleY(thing.getDouble("scaleY"));
        }
        if(thing.valueExists("scaleZ")){
            node.setScaleZ(thing.getDouble("scaleZ"));
        }
        if(thing.valueExists("style")){
            String style = JavaFXUtils.getString(thing, "style", actionContext);
            if(style != null) {
                node.setStyle(style);
            }
        }
        if(thing.valueExists("translateX")){
            node.setTranslateX(thing.getDouble("translateX"));
        }
        if(thing.valueExists("translateY")){
            node.setTranslateY(thing.getDouble("translateY"));
        }
        if(thing.valueExists("translateZ")){
            node.setTranslateZ(thing.getDouble("translateZ"));
        }
        if(thing.valueExists("visible")){
            node.setVisible(thing.getBoolean("visible"));
        }

        Designer.attach(thing, node, actionContext);
	}
}
